//
//  JPayProductView.m
//  HeadIndustry
//
//  Created by jun on 2017/9/5.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JPayProductView.h"

@interface JPayProductView()

//显示照片
@property (nonatomic,strong) UIImageView *ImageView;
//商品名
@property (nonatomic,strong) YYLabel *nameLabel;
//尺寸
@property (nonatomic,strong) YYLabel *sizeLabel;
//时间
@property (nonatomic,strong) YYLabel *dateLabel;
//价格
@property (nonatomic,strong) YYLabel *priceLabel;
//数量
@property (nonatomic,strong)YYLabel *numberLabel;

@end

@implementation JPayProductView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = kRGBColor(245, 245, 245);
        self.opaque = NO;
        [self setUpView];
    }
    return  self;
}

- (void)setUpView {
    //显示照片
    UIImageView* imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@"default_pic_1"];
    imageView.frame = CGRectMake(15, 5, self.height - 10, self.height - 10);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:imageView];
    self.ImageView = imageView;
    
    CGFloat width = self.width - imageView.right - 30 ;
    
    //商品名
    YYLabel* nameLabel = [[YYLabel alloc]init];
    nameLabel.frame = CGRectMake(imageView.right + 10, 10, width, 40);
    nameLabel.font = [UIFont systemFontOfSize:15];
    nameLabel.numberOfLines = 0;
    [self addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    //尺寸
    YYLabel* sizeLabel = [[YYLabel alloc]init];
    sizeLabel.frame = CGRectMake(nameLabel.left, nameLabel.bottom, width, 20);
    sizeLabel.textColor = kRGBColor(150, 150, 150);
    sizeLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:sizeLabel];
    self.sizeLabel = sizeLabel;
    
    //单价
    YYLabel* dateLabel = [[YYLabel alloc]init];
    dateLabel.frame = CGRectMake(nameLabel.left, sizeLabel.bottom , width, 20);
    dateLabel.font = [UIFont systemFontOfSize:12];
    dateLabel.textColor = [UIColor redColor];
    [self addSubview:dateLabel];
    self.dateLabel = dateLabel;
    
    //数量
    YYLabel* priceLabel = [[YYLabel alloc]init];
    priceLabel.frame = CGRectMake(self.right - width - 10, sizeLabel.bottom, width, 20);
    priceLabel.font = [UIFont boldSystemFontOfSize:12];
    priceLabel.textColor = [UIColor blackColor];
    priceLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:priceLabel];
    self.priceLabel = priceLabel;
}

#pragma mark - public method
- (void)reloadDataWithModel:(JShopCarDetailModel*)model {
    
    self.ImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImgUrl]]];
    self.nameLabel.text = model.ProductName;
    self.priceLabel.text = [NSString stringWithFormat:@"X%ld",(long)model.Quantity];
    self.dateLabel.text = model.CustomerEnteredPriceText;
    
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[model.AttributesXml dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    
    self.sizeLabel.attributedText = attrStr;
}

- (void)reloadOrderDataWithModel:(JWaitPayDetailModel *)model
{
    self.ImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImgUrl]]];
    self.nameLabel.text = model.ProductName;
    self.priceLabel.text = [NSString stringWithFormat:@"X%ld",(long)model.Quantity];
    self.dateLabel.text = model.PriceText;
    
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[model.AttributesXml dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    
    self.sizeLabel.attributedText = attrStr;
}

@end
